package cn.lg.soar.flow.api.model.node;

import cn.lg.soar.flow.api.enums.NodeStatusEnum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Data
public class TimerNode implements Node, Serializable {

    private String key;
    private String name;
    private String description;
    private NodeStatusEnum status;

    private List<ProcessListener> processListeners;

    // 构造函数
    public TimerNode() {}

    public TimerNode(String key, String name) {
        this.key = key;
        this.name = name;
    }

    // Getters and Setters
    @JsonProperty("type")
    @Override
    public String getType() { return "timer"; }

    @Override
    public String toXmlString() {
        StringBuilder sb = new StringBuilder();
        // 开始 boundaryEvent 标签
        /*sb.append("<boundaryEvent id=\"").append(key).append("\" ")
                .append("attachedToRef=\"").append(attachedToRef).append("\" ");

        // cancelActivity 默认为 true，可配置
        boolean cancelAct = cancelActivity == null || cancelActivity; // 默认 true
        sb.append("cancelActivity=\"").append(cancelAct).append("\">\n");

        // 添加 timerEventDefinition
        sb.append("      <timerEventDefinition>\n");
        if (DataUtil.isValuable(timeDuration)) {
            sb.append("        <timeDuration>")
                    .append(XmlUtils.escapeXml(timeDuration))
                    .append("</timeDuration>\n");
        } else if (DataUtil.isValuable(timeDate)) {
            sb.append("        <timeDate>")
                    .append(XmlUtils.escapeXml(timeDate))
                    .append("</timeDate>\n");
        } else if (DataUtil.isValuable(timeCycle)) {
            sb.append("        <timeCycle>")
                    .append(XmlUtils.escapeXml(timeCycle))
                    .append("</timeCycle>\n");
        }
        sb.append("      </timerEventDefinition>\n");
        // 添加执行监听器
        if (DataUtil.isValuable(processListeners)) {
            sb.append("<extensionElements>");
            if (DataUtil.isValuable(processListeners)) {
                for (ProcessListener x : processListeners) {
                    sb.append("<flowable:executionListener event=\"").append(x.getEvent()).append("\" ")
                            .append(Boolean.TRUE.equals(x.getIsExpression()) ? "expression" : "class")
                            .append("=\"").append(XmlUtils.escapeXml(x.getValue())).append("\" />\n");
                }
            }
            sb.append("</extensionElements>\n");
        }
        // 结束 boundaryEvent
        sb.append("    </boundaryEvent>\n");*/
        return sb.toString();
    }
}